package org.wu.framework.web.request;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.util.List;

/**
 * request 拦截
 *
 * @param <Handler>  处理器
 */
public interface LazyInterceptorRegistry<Handler> {
    /**
     * @see InterceptorRegistration#addPathPatterns(List)
     */
    default List<String> addPathPatterns() {
        return List.of("/**");
    }


    /**
     * @see InterceptorRegistration#excludePathPatterns(List)
     */
    default List<String> excludePathPatterns() {
        return List.of();
    }


    /**
     * 请求 处理之前
     *
     * @param request  current HTTP request
     * @param response current HTTP response
     * @param handler  chosen handler to execute, for type and/or instance evaluation
     * @return boolean 返回 false 请求拦截无法进入 返回true 请求放行
     * @throws Exception
     */
    default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Handler handler)
            throws Exception {

        return true;
    }


    /**
     * 请求处理成功
     *
     * @param request  current HTTP request
     * @param response current HTTP response
     * @param handler  the handler (or {@link HandlerMethod}) that started asynchronous
     *                 execution, for type and/or instance examination
     * @throws Exception
     */
    default void postHandle(HttpServletRequest request, HttpServletResponse response, Handler handler) throws Exception {
    }


    default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Handler handler,
                                  Exception ex) throws Exception {
    }


}
